import {
	defineStore
} from 'pinia'

import {
	ref
} from 'vue'
export const userStore = defineStore("user", () => {
	// 定义token令牌
	let token = ref("")
	//已登录用户信息
	let userInfo = ref({})
	//登录状态
	let isLogin = ref(false)
	let currentPos = ref({
		latitude: 108.9397,
		longitude: 34.342,
	})

	let hasPos = ref(false)
	// 登陆成功后，保持用户信息
	function addUserInfo(id, username, phone, email) {
		this.userInfo.id=id
		this.userInfo.username=username;
		this.userInfo.email=email;
		this.userInfo.phone=phone;
		this.token=token            
		this.isLogin=true
	}
	// 清除用户登录状态
	function clearUserInfo() {
		this.userInfo = {}
		this.isLogin = false
		this.token = ""
	}

	function setPos(lat, lon) {
		currentPos.latitude = lat
		currentPos.longitude = lon
		hasPos.value = true
	}
	return {
		token,
		userInfo,
		isLogin,
		addUserInfo,
		clearUserInfo,
		hasPos,
		setPos,
		currentPos
	}
})